import tkinter as tk
from tkinter import filedialog

root = tk.Tk()
root.geometry('500x300')

tk.Button(root, text="获取文件名", command=lambda: print(filedialog.askopenfilename())).pack()
tk.Button(root, text="获取文件名（指定路径）", command=lambda: print(filedialog.askopenfilename(initialdir='C:\\'))).pack()
tk.Button(root, text="获取文件名（多个）", command=lambda: print(filedialog.askopenfilenames())).pack()
tk.Button(root, text="获取文件名（指定类型）",
          command=lambda: print(filedialog.askopenfilenames(filetypes=[('Python', '.py'), ('Python', '.pyc')]))).pack()


def read_file():
    # 有缺陷，会调用系统默认的编码格式
    file = filedialog.askopenfile(mode='rb')
    print(file.read())


tk.Button(root, text="指定文件类读取文件", command=read_file).pack()

root.mainloop()